package com.aaa.dang.modules.user.Controller;

import com.aaa.dang.common.systemconst.ISystemConst;
import com.aaa.dang.common.util.ResultModel;
import com.aaa.dang.modules.user.service.IRoomChangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.xml.transform.Result;
import java.util.HashMap;
import java.util.Map;

/**
 * @author JinChaoLiang
 * @calss QY87
 * @description 进行房间信息的更换
 * @date 2018/12/17
 */
@Controller
@RequestMapping("/user")
public class RoomChangeController {

    @Autowired
    private IRoomChangeService changeService;

    /**
     * 跳转页面
     * @return
     */
    @RequestMapping("/toGetInfo")
    public String getUserAndRoomInfo(){
        return "/user/roomchange";
    }

    @RequestMapping("/toGetInfoTwo")
    public String getUserAndRoomInfoTwo(){
        return "/user/changetoempty";
    }

    @RequestMapping("/getInfoByUsername")
    @ResponseBody
    public Map<String,Object> getInfoByUsername(String username){
        Map<String, Object> map1 = new HashMap<>();
        Map<String,Object> map = changeService.getInfoByUsername(username);
        if (map == null){
            map1.put("code",ISystemConst.FAULT_CODE);
            return map1;
        } else {
            return map;
        }
    }

    @RequestMapping("/changeRoom")
    @ResponseBody
    public int changeRoom(@RequestParam int id, int id1){
        /*System.out.println(id);
        System.out.println(id1);*/
        return changeService.updateRoom(id,id1);
    }

    @RequestMapping("/getRoomByBuildId")
    @ResponseBody
    public ResultModel getRoomByBuildId(@RequestParam Map<String,Object> map){
        System.out.println(map);
        ResultModel rm = new ResultModel();
        rm = changeService.getRoomByBuildId(map);
        return rm;
    }
    @RequestMapping("/getBedByBuildId")
    @ResponseBody
    public ResultModel getBedByBuildId(int roomid){
        System.out.println(roomid);
        ResultModel rm = new ResultModel();
        rm = changeService.getBedByBuildId(roomid);
        return rm;
    }

    @RequestMapping("/changeToEmptyRoom")
    @ResponseBody
    public ResultModel changeToEmptyRoom(@RequestParam Map<String,Object> map){
        ResultModel rm = new ResultModel();
        rm.setCode(changeService.updateEmptyRoom(map));
        rm.setData("");
        return rm;
    }
}
